<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="200px">
      <el-form-item label="启用口罩识别" prop="enableMask">
        <el-radio-group v-model="form.enableMask">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="图像质量" prop="imageQuality">
        <el-input v-model="form.imageQuality" placeholder="请输入图像质量" />
      </el-form-item>
      <el-form-item label="带口罩图像质量" prop="maskImageQuality">
        <el-input v-model="form.maskImageQuality" placeholder="请输入带口罩图像质量" />
      </el-form-item>
      <el-form-item label="人脸对比阀值" prop="similarThreshold">
        <el-input v-model="form.similarThreshold" placeholder="请输入人脸对比阀值" />
      </el-form-item>
      <el-form-item label="注册比对阀值" prop="regSimilarThreshold">
        <el-input v-model="form.regSimilarThreshold" placeholder="请输入注册比对阀值" />
      </el-form-item>
      <el-form-item label="戴口罩比对阀值" prop="maskSimilarThreshold">
        <el-input v-model="form.maskSimilarThreshold" placeholder="请输入戴口罩比对阀值" />
      </el-form-item>
      <el-form-item label="RGB活体检测阀值" prop="rgbThreshold">
        <el-input v-model="form.rgbThreshold" placeholder="请输入RGB活体检测阀值" />
      </el-form-item>
      <el-form-item label="IR活体检测阀值" prop="irThreshold">
        <el-input v-model="form.irThreshold" placeholder="请输入IR活体检测阀值" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { listFaceconfig, getFaceconfig, delFaceconfig, addFaceconfig, updateFaceconfig } from "@/api/faceplus/faceconfig";

export default {
  name: "Faceconfig",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表单参数
      form: {
        id: 1,
        enableMask: 0,
        imageQuality: "0.1",
        maskImageQuality: "0.1",
        similarThreshold: "0.85",
        regSimilarThreshold: "0.85",
        maskSimilarThreshold: "0.85",
        rgbThreshold: "0.5",
        irThreshold: "0.7"
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getConfig();
  },
  methods: {
    /** 查询人脸库配置列表 */
    getConfig() {
      this.loading = true;
      getFaceconfig(1).then(response => {
        this.form = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: 1,
        enableMask: 0,
        imageQuality: "0.1",
        maskImageQuality: "0.1",
        similarThreshold: "0.85",
        regSimilarThreshold: "0.85",
        maskSimilarThreshold: "0.85",
        rgbThreshold: "0.5",
        irThreshold: "0.7"
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFaceconfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFaceconfig(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    }
  }
};
</script>

<style scoped>
.dialog-footer {
  text-align: center;
  margin-top: 20px;
}
</style>
